#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <functional>
#include <boost/bind.hpp>
#include <boost/timer.hpp>
#include <boost/shared_ptr.hpp>

using namespace std;

size_t jstrlen(const char * p)
{
	size_t sz = 0;
	while(*p++)
		++sz;
	return sz;
}

char* jstrcpy(char *d, const char *s)
{
	char *p = d;
	while(*d++ = *s++)
		;
	return p;
}

char* jstrcat(char *d, const char *s)
{
	char *p = d;
	while(*d++)
		;
	--d;
	while(*d++ = *s++)
		;
	return p;
}

int jstrcmp(const char *d, const char *s)
{
	while(*d)
	{
		if( !*s )
			return -1;
		else if(*d > *s)
			return -1;
		else if(*d < *s)
			return 1;
		else{
			++d;
			++s;
		}
	}

	if( !*s )
		return 0;
	else 
		return 1;
}

void jmemset(void *p, signed char c, size_t sz)
{
	signed char *pp = static_cast<signed char *>(p);
	while(sz--)
		*pp-- = c;

}

int main(int argc, char **argv)
{
	cout<<jstrlen("")<<endl;
	cout<<jstrlen("A")<<endl;
	cout<<jstrlen("AA")<<endl;

	char buf1[100];
	char buf2[100];
	jstrcpy(buf1, "Hello,");
	jstrcpy(buf2, "World!");

	cout<<buf1<<buf2<<endl;

	jstrcat(buf1,buf2);
	cout<<buf1<<endl;

	cout<<jstrcmp("","")<<endl;
	cout<<jstrcmp("A","")<<endl;
	cout<<jstrcmp("A","A")<<endl;
	cout<<jstrcmp("","A")<<endl;

	int ia = 9999;
	jmemset(&ia,0,sizeof(int));
	cout<<ia<<endl;
	return 0;
}
